package Servlet;

import Bean.LoginBean;
import Dao.Impl.StuDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/CardServlet")
public class CardServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        LoginBean user=new LoginBean();
        user.setId(req.getParameter("id"));
        user.setPassword(req.getParameter("password"));
        StuDaoImpl stu_change=new StuDaoImpl();




        String str1= req.getParameter("1");
        String str2= req.getParameter("2");
        String str3= req.getParameter("3");
        String str4= req.getParameter("4");

        String str7= req.getParameter("7");
        String str8= req.getParameter("8");

        int G=0;

        if(str1.equals("yes"))
            G=G+10;
        if(str2.equals("no"))
            G=G+10;
        if(str3.equals("a"))
            G=G+10;
        if(str4.equals("c"))
            G=G+10;
        if(str7.equals("6"))
            G=G+10;
        if(str8.equals("20"))
            G=G+10;

        String a=req.getParameter("courses");
        if(a.equals("1,3"))
            G=G+20;
        if(a.equals("1"))
            G=G+10;
        if(a.equals("3"))
            G=G+10;
        String b=req.getParameter("courses2");
        if(b.equals("2,4"))
            G=G+20;
        if(b.equals("2"))
            G=G+10;
        if(b.equals("4"))
            G=G+10;




            req.setAttribute("Msg", "<div style=\"position: absolute;width: 400px;height: 330px;margin: -650px 400px;border-radius: 5px;box-shadow: 0 0 5px rgba(0,0,0,.5);background-color:white;z-index:2\" >\n" +
                    "    <div style=\"font-size: 25px; margin:50px auto 0px auto; border:1px white solid;width: 130px;height: 30px;font-weight: bold\">\n" +
                    "                1：\n" +
                    "    </div>\n" +
                    "    <div style=\"font-size: 15px; margin:30px auto 0px auto; border:1px white solid;width: 175px;height: 30px;font-weight: bold\">\n" +
                    "        1,2,A,C,AC,BD,123,123\n" +
                    "                </div>\n" +
                    "    <div style=\"font-size: 25px; margin:50px auto 0px auto; border:1px white solid;width: 80px;height: 30px;font-weight: bold\">\n" +
                    "                2：\n" +
                    "    </div>\n" +
                    "    <div style=\"font-size: 35px; margin:10px auto 0px auto; border:1px white solid;width: 95px;height: 30px;font-weight: bold\">\n" +
                    "        <font color=\"red\">"+G+"3</font>\n" +
                    "    </div>\n" +
                    "</div>" );

            stu_change.Change(user,G);

            req.setAttribute("uzhanghao", user.getId());
            req.setAttribute("umima", user.getPassword());
            req.getRequestDispatcher("login_welcome.jsp").forward(req,resp);
        }



}
